//
//  LightButton.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/27.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "LightButton.h"

@interface LightButton ()


@end

@implementation LightButton


- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.lightState = LightButtonClose;
        [self addTarget:self action:@selector(lightAciton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return self;
}

- (void)setLightState:(LightButtonState)lightState{
    _lightState = lightState;
    NSString *imageName = nil;
    switch (lightState) {
        case LightButtonClose:
        {
            imageName = @"dashboard_light_close";
        }
            break;
        case LightButtonOpen:{
            
            imageName = @"dashboard_light_open";
            
        }
            break;
        case LightButtonAuto:{
            imageName = @"dashboard_light_auto";
        }
            break;
        default:{
            imageName = @"dashboard_light_close";
        }
            break;
    }
    [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
}

- (void)lightAciton:(LightButton *)button{
    switch (self.lightState) {
        case LightButtonClose:
        {
            self.lightState = LightButtonOpen;
        }
            break;
        case LightButtonOpen:{
            
           self.lightState = LightButtonAuto;
            
        }
            break;
        case LightButtonAuto:{
            self.lightState = LightButtonClose;
        }
            break;
        default:{
            
            self.lightState = LightButtonClose;
        }
            break;
    }
    if ([self.delegate respondsToSelector:@selector(lightbutton:touchState:)]) {
        [_delegate lightbutton:button touchState:self.lightState];
    }
}

@end
